﻿@{
    ViewBag.Title = "NewIndex";
    Layout = "~/Views/Shared/_LayoutIndex.cshtml";
}

<script>
    var _organizeid = '@LeSoft.Application.Code.OperatorProvider.Provider.Current().CompanyId';
    var _pstructId = "";
    $(function () {
        InitialPage();
        GetTree();
        GetGrid();
    });
    //初始化页面
    function InitialPage() {
        //layout布局
        $('#layout').layout({
            applyDemoStyles: true,
            onresize: function () {
                $(window).resize()
            }
        });
        //resize重设(表格、树形)宽高
        $(window).resize(function (e) {
            window.setTimeout(function () {
                $('#gridTable').setGridWidth($('.gridPanel').width());
                $("#gridTable").setGridHeight($(window).height() - 171.5);
                $("#itemTree").setTreeHeight($(window).height() - 31.5);
            }, 200);
            e.stopPropagation();

        });
        //var wc = document.getElementsByClassName("ui-layout-center")[0];
        //var we = document.getElementsByClassName("ui-layout-east")[0];
        //var we2 = document.getElementsByClassName("ui-layout-resizer")[1];
        //var width = wc.style.width.split('px')[0] * 0.9;
        //var width2 = parseFloat(wc.style.width.split('px')[0] * 0.1) + parseFloat(we.style.width.split('px')[0]);
        //var width3 = parseFloat(we2.style.right.split('px')[0]) + parseFloat(wc.style.width.split('px')[0] * 0.15);
        //wc.style.width = width + "px";
        //we.style.width = width2 + "px";
        //we2.style.right = width2 + "px";
        GetStatisticsTotal();
    }

    function GetTree() {
        var item = {
            url: "../../BaseManage/Organize/GetTreeJsonById",
            height: $(window).height() - 31.5,
            onnodeclick: function (item) {
                if (_organizeid != item.id) {
                    _organizeid = item.id;
                    GridReload();
                    GetStatisticsTotal();
                }
            }
        };
        //初始化
        $("#itemTree").treeview(item);
    }
    //加载表格
    function GetGrid() {
        var selectedRowIndex = 0;
        var $gridTable = $('#gridTable');
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["OrganizeId"] = _organizeid;
        $gridTable.jqGrid({
            url: "../../ResourceManage/RS_PStructs/GetStatistics",
            postData: { queryJson: JSON.stringify(queryJson) },
            datatype: "json",
            height: $(window).height() - 171.5,
            autowidth: true,
            colModel: [
                { label: '主键', name: 'id', hidden: true },
                { label: "项目名称", name: "name", width: 200, align: "left", sortable: true },
                {
                    label: "总建筑面积", name: "", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return (rowObject.roomsum + rowObject.garagesum).toFixed(4);
                    }
                },
                { label: "总房屋数", name: "roomcount", width: 100, align: "left", sortable: true },
                { label: "总车位数", name: "pgaragecount", width: 100, align: "left", sortable: true, hidden: true },
                { label: "入住面积", name: "checkarea", width: 100, align: "left", sortable: true },
                {
                    label: "空置面积", name: "", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        return (rowObject.roomsum + rowObject.garagesum - rowObject.checkarea).toFixed(4);
                    }
                },
                { label: "入住房屋数", name: "checkroom", width: 100, align: "left", sortable: true },
                { label: "空置房屋数", name: "vacancyroom", width: 100, align: "left", sortable: true },
                {
                    label: "入住率", name: "", width: 100, align: "left", sortable: true,
                    formatter: function (cellvalue, options, rowObject) {
                        if (!!rowObject.roomcount)
                            return (rowObject.checkroom / rowObject.roomcount * 100).toFixed(4) + "%";
                        else return "";
                    }
                },
                { label: "附加说明", name: "Memo", width: 100, align: "left", sortable: false }
            ],
            viewrecords: true,
            rowNum: 30,
            rowList: [30, 50, 100],
            pager: "#gridPager",
            sortable: true,
            sortname: 'name',
            sortorder: 'asc',
            rownumbers: false,
            shrinkToFit: false,
            gridview: true,
            onSelectRow: function (rowid) {
                selectedRowIndex = $("#" + this.id).getGridParam('selrow');
                _pstructId = $gridTable.getRowData(rowid).id;
            },
            gridComplete: function () {
                $("#" + this.id).setSelection(selectedRowIndex, false);
            }
        });
    }

    function GridReload() {
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["OrganizeId"] = _organizeid;
        queryJson["keyword"] = $("#txt_Keyword").val();
        queryJson["Type"] = $('#queryCondition').find('.dropdown-text').attr('data-value');
        $('#gridTable').jqGrid('setGridParam', {
            postData: {
                queryJson: JSON.stringify(queryJson)
            }
        }).trigger('reloadGrid');
    }

    function GetStatisticsTotal() {
        var queryJson = $("#queryCondition").GetWebControls();
        queryJson["OrganizeId"] = _organizeid;
        $.SetForm({
            url: "../../ResourceManage/RS_PStructs/GetStatisticsTotal",
            param: { queryJson: JSON.stringify(queryJson) },
            success: function (data) {
                //var roomsum = !data[0].roomsum ? 0 : data[0].roomsum; garagesum = !data[0].garagesum ? 0 : data[0].garagesum; checkarea = !data[0].checkarea ? 0 : data[0].checkarea;
                $("#RoomSum").html(data[0].roomsum);
                $("#Count").html(data[0].count);
                $("#SumArea").html(((data[0].sumarea)/10000).toFixed(4));
                //$("#GarageSum").html(!data[0].pgaragecount ? 0 : data[0].pgaragecount);
                $("#CheckArea").html((data[0].checkarea/10000).toFixed(4));
                $("#VacancyArea").html(((data[0].vacancyarea) / 10000).toFixed(4));
                $("#CheckRoom").html(data[0].checkroom);
                $("#VacancyRoom").html(data[0].vacancyroom);
            }
        });
    }

    //新增
    function btn_add() {
        dialogOpen({
            id: "Form",
            title: '添加房产',
            url: '/ResourceManage/RS_PStructs/Form?organizeId=' + _organizeid,
            width: "1000px",
            height: "850px",
            callBack: function (iframeId) {
                top.frames[iframeId].AcceptClick();
            }
        });
    };

    function btn_edit() {
        var keyValue = $("#gridTable").jqGridRowValue("id");
        if (checkedRow(keyValue)) {
            var organizeId = $("#gridTable").jqGridRowValue("OrganizeId");
            dialogOpen({
                id: "Form",
                title: '修改房产',
                url: '/ResourceManage/RS_PStructs/Form?organizeId=' + organizeId + "&keyValue=" + keyValue,
                width: "1000px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }

    //删除
    function btn_delete() {
        var keyValue = $("#gridTable").jqGridRowValue("Id");
        if (keyValue) {
            $.RemoveForm({
                url: "../../ResourceManage/RS_PStructs/RemoveForm",
                param: { keyValue: keyValue },
                success: function (data) {
                    $("#gridTable").resetSelection();
                    $("#gridTable").trigger("reloadGrid");
                }
            })
        } else {
            dialogMsg('请选择需要删除的数据项！', 0);
        }
    }

    function btn_Details(keyValue) {
        if (checkedRow(keyValue)) {
            dialogOpen({
                id: "Form",
                title: '查看详情',
                btn: null,
                url: '/ResourceManage/RS_PStructs/Detail?keyValue=' + keyValue,
                width: "1000px",
                height: "850px",
                callBack: function (iframeId) {
                    top.frames[iframeId].AcceptClick();
                }
            })
        }
    }

    function btn_detailsIndex() {
        top.tablist.newTab({
            id: "PStructList",
            title: '列表查看',
            closed: true,
            icon: "fa fa-eye",
            url: top.contentPath + '/ResourceManage/RS_PStructs/Index?OrganizeId=' + _organizeid + "&PstructId=" + _pstructId
        });
    }
    function btn_detailsColor() {
        var keyValue = "";
        top.tablist.newTab({
            id: "PSColor",
            title: '房态表查看',
            closed: true,
            icon: "fa fa-eye",
            url: top.contentPath + '/ResourceManage/PStructColor/Index?keyValue=' + _pstructId
        });
    }

    function btn_export() {
        location.href = "../../ResourceManage/RS_PStructs/GetExportList";
    }

    function btn_disabled() {
        $.SaveForm({
            url: "../../ResourceManage/RS_PStructs/ExcelImport",
            loading: "正在保存数据...",
            success: function () {
                // $.currentIframe().$("#gridTable").resetSelection();
            }
        })
    }

</script>
<div style="position:absolute;top:0; right:40px;z-index:1000;background:rgba(0, 0, 0, 0.1);padding:10px;border-radius:0px 0px 5px 5px;">
    <div class="btn-group">
        <a id="lr-list" onclick="btn_detailsIndex()" class="btn btn-default"><span class="fa fa-eye"></span> &nbsp;列表查看</a>
        <a id="lr-Graph" onclick="btn_detailsColor()" class="btn btn-default"><span class="fa fa-eye"></span> &nbsp;房态图</a>
    </div>
    <script>$('.btn-group').authorizeButton()</script>
</div>
<div class="ui-layout" id="layout" style="height: 100%; width: 100%;">
    <div class="ui-layout-west">
        <div class="west-Panel" style="height: 98%;">
            <div id="itemTree"></div>
        </div>
    </div>
    <div class="ui-layout-center">
        <div class="center-Panel">
            <div>
                <div class="title-search" style="padding-right:200px; height: 65px; margin-top: 15px;margin-bottom:15px;">
                    <table class="form">
                        <tr>
                            <th><h2 id="Count" style="display: inline;"></h2>个</th>
                            <th><h2 id="SumArea" style="display: inline;"></h2>万平</th>
                            <th><h2 id="RoomSum" style="display: inline;"></h2>套</th>
                            <th style="display:none;"><h2 id="GarageSum" style="display: inline;"></h2>个</th>
                            <th><h2 id="CheckArea" style="display: inline;"></h2>万平</th>
                            <th><h2 id="VacancyArea" style="display: inline;"></h2>万平</th>
                            <th><h2 id="CheckRoom" style="display: inline;"></h2>套</th>
                            <th><h2 id="VacancyRoom" style="display: inline;"></h2>套</th>
                        </tr>
                        <tr style="text-align:center;">
                            <td>项目总数</td>
                            <td>总建筑面积</td>
                            <td>总房屋数</td>
                            <td style="display:none;">总车位数</td>
                            <td>入住面积</td>
                            <td>空置面积</td>
                            <td>入住房屋数</td>
                            <td>空置房屋数</td>
                        </tr>
                    </table>
                </div>
            </div>
            <div class="gridPanel">
                <table id="gridTable"></table>
                <div id="gridPager"></div>
            </div>
        </div>
    </div>
    @*<div class="ui-layout-east" style="display:none;">
            <div class="center-Panel" style="height:98%;">
                <ul>
                    <li style="margin-top:5px;">
                        <a id="lr-add" class="btn btn-default" onclick="btn_add()"><i class="fa fa-plus"></i>&nbsp;新增房产项目</a>
                    </li>
                    <li style="margin-top:5px;">
                        <a id="lr-edit" class="btn btn-default" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>&nbsp;编辑房产项目</a>
                    </li>
                    <li style="margin-top:5px;">
                        <a id="lr-delete" class="btn btn-default" onclick="btn_delete()"><i class="fa fa-trash-o"></i>&nbsp;删除房产项目</a>
                    </li>
                    <li style="margin-top: 5px;">
                        <a id="lr-delete" class="btn btn-default" onclick=""><i class="fa fa-eye"></i>&nbsp;查看房产项目信息</a>
                    </li>
                    <li style="margin-top: 5px;">
                        <a id="lr-delete" class="btn btn-default" onclick="btn_detailsIndex()"><i class="fa fa-eye"></i>&nbsp;列表查看房屋信息</a>
                    </li>
                    <li style="margin-top: 5px;">
                        <a id="lr-delete" class="btn btn-default" onclick="btn_detailsColor()"><i class="fa fa-eye"></i>&nbsp;房态表查看房屋明细</a>
                    </li>
                    <li style="margin-top: 5px;">
                        <a id="lr-delete" class="btn btn-default" onclick=""><i class="fa fa-eye"></i>&nbsp;剖面图查看房屋明细</a>
                    </li>
                </ul>
            </div>
        </div>
        <style>
            .ui-layout-east > .center-Panel > ul {
                padding-left: 20px;
            }

                .ui-layout-east > .center-Panel > ul > li > a {
                    width: 150px;
                    border-left: none;
                    border-right: none;
                    border-top: none;
                }
        </style>*@
</div>